package org.t411.api.scrapper;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import android.util.Log;

public class GetMessageContentTask extends HttpAsyncTask<MessageEntry, MessageEntry> {
	public final static String messageContentUrl = "http://www.t411.me/mailbox/mail/?id=";

	@Override
	protected MessageEntry doInBackground(MessageEntry... arg0) {
		Log.v(this.getClass().getSimpleName(), String.format("begin (%s)", buildUrl(arg0[0].id)));
		final HttpGet request = new HttpGet(buildUrl(arg0[0].id));
		final HttpResponse httpResponse = browser.execute(request);
		final Document htmlResponse = Jsoup.parse(getStringContent(httpResponse));
		
		HeaderFooterScrapper.readPage(htmlResponse, profile);
		
		arg0[0].content = htmlResponse.select("div.msg").first().text();
		return arg0[0];
	}
	
	public static String buildUrl(Integer request) { return messageContentUrl+request; }
}
